$(function () {
	 $('#datetimepicker1').datetimepicker({  
	        format: 'YYYY-MM-DD',  
	        locale: moment.locale('zh-cn')  
	    });  
	    $('#datetimepicker2').datetimepicker({  
	        format: 'YYYY-MM-DD hh:mm',  
	        locale: moment.locale('zh-cn')  
	    }); 
	    
	    $("#LeaveinfoGrid").jqGrid({
	        url: baseURL + 'generator/employee/list',
	        datatype: "json",
	        colModel: [			
				{ label: '员工序号', name: 'employeeno', index: 'employeeNo', width: 100, key: true },
				{ label: '员工角色', name: 'employeetype', index: 'employeeType', width: 100 }, 			
				{ label: '转正日期', name: 'confirmdate', index: 'confirmDate', width: 80 ,formatter:"date", formatoptions: {newformat:'Y年m月d日'}}, 			
				{ label: '员工姓名', name: 'name', index: 'Name', width: 100 }, 			
				{ label: '员工性别', name: 'gender', index: 'gender', width: 100 }, 			
				{ label: '员工生日', name: 'birthday', index: 'birthday', width: 100 ,formatter:"date", formatoptions: {newformat:'Y年m月d日'} }, 			
				{ label: '员工证件类型', name: 'idtype', index: 'IdType', width: 100 ,formatter: function(value, options, row){
					var result = "";
					$.ajax({
						type: "POST",
					    url: baseURL + "generator/cardtype/info/"+value,
		                contentType: "application/json",
					    async : false,
					    success: function(r){
					    	if(r.code === 0){
					    		result = r.cardtype.cardname;
							}
						}
					});
					return result;
				}}, 			
				{ label: '员工证件号码', name: 'idno', index: 'IDNo', width: 100 }, 			
				{ label: '合同起期', name: 'startdate', index: 'Startdate', width: 100 ,formatter:"date", formatoptions: {newformat:'Y年m月d日'}}, 			
				{ label: '合同止期', name: 'enddate', index: 'EndDate', width: 100 ,formatter:"date", formatoptions: {newformat:'Y年m月d日'}}, 			
				{ label: '入职日期', name: 'entrydate', index: 'EntryDate', width: 100 ,formatter:"date", formatoptions: {newformat:'Y年m月d日'}}, 			
				{ label: '校区', name: 'schoolno', index: 'schoolNo', width: 50 ,formatter: function(value, options, row){
					var result = "";
					$.ajax({
						type: "POST",
					    url: baseURL + "generator/school/info/"+value,
		                contentType: "application/json",
					    async : false,
					    success: function(r){
					    	if(r.code === 0){
					    		result = r.school.schoolname;
							}
						}
					});
					return result;
				}}, 			
				{ label: '部门', name: 'deptno', index: 'deptNo', width: 50 ,formatter: function(value, options, row){
					var result = "";
					$.ajax({
						type: "POST",
					    url: baseURL + "generator/department/info/"+value,
		                contentType: "application/json",
					    async : false,
					    success: function(r){
					    	if(r.code === 0){
					    		result = r.department.name;
							}
						}
					});
					return result;
				}}, 			
				{ label: '职务', name: 'job', index: 'job', width: 80 ,formatter: function(value, options, row){
					var result = "";
					$.ajax({
						type: "POST",
					    url: baseURL + "generator/jobcode/info/"+value,
		                contentType: "application/json",
					    async : false,
					    success: function(r){
					    	if(r.code === 0){
					    		result = r.jobcode.dutyname;
							}
						}
					});
					return result;
				}}, 			
				{ label: '职级', name: 'jobgrade', index: 'jobGrade', width: 80 ,formatter: function(value, options, row){
					var result = "";
					$.ajax({
						type: "POST",
					    url: baseURL + "generator/jobgradecode/info/"+value,
		                contentType: "application/json",
					    async : false,
					    success: function(r){
					    	if(r.code === 0){
					    		result = r.jobgradecode.jobgradename;
							}
						}
					});
					return result;
				}}, 			
				{ label: '工资基准', name: 'salarygrade', index: 'salaryGrade', width: 80 }, 			
				{ label: '联系电话', name: 'phone', index: 'phone', width: 80 }, 			
				{ label: '微信', name: 'webchat', index: 'webchat', width: 80 }, 			
				{ label: '紧急联系人', name: 'contacter', index: 'contacter', width: 80 }, 			
				{ label: '紧急联系人电话', name: 'conphone', index: 'conphone', width: 80 }, 			
				{ label: '备用1', name: 'standbyflag1', index: 'StandByFlag1', width: 80 }, 			
				{ label: '备用2', name: 'standbyflag2', index: 'StandByFlag2', width: 80 }, 			
				{ label: '备用3', name: 'standbyflag3', index: 'StandByFlag3', width: 80 }		
	        ],
			viewrecords: true,
	        height: 385,
	        rowNum: 10,
			rowList : [10,30,50],
	        rownumbers: true, 
	        rownumWidth: 25, 
	        autowidth:true,
	        multiselect: true,
	        pager: "#LeaveinfojqGridPager",
	        jsonReader : {
	            root: "page.list",
	            page: "page.currPage",
	            total: "page.totalPage",
	            records: "page.totalCount"
	        },
	        prmNames : {
	            page:"page", 
	            rows:"limit", 
	            order: "order"
	        },
	        gridComplete:function(){
	        	//隐藏grid底部滚动条
	        	$("#LeaveinfoGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
	        }
	    });
	    
    $("#jqGrid").jqGrid({
        url: baseURL + 'generator/leaveinfo/list',
        datatype: "json",
        colModel: [			
			{ label: '序号', name: 'leaveno', index: 'leaveNo', width: 50, key: true },
			{ label: '请假日期', name: 'leavedate', index: 'leaveDate', width: 80 }, 			
			{ label: '客户号', name: 'employeeno', index: 'employeeNo', width: 80 ,formatter: function(value, options, row){
				var result = "";
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/employee/info/"+value,
	                contentType: "application/json",
				    async : false,
				    success: function(r){
				    	if(r.code === 0){
				    		result = r.employee.name;
						}
					}
				});
				return result;
			}}, 			
			{ label: '请假原因', name: 'leavereason', index: 'leaveReason', width: 80 }, 			
			{ label: '请假备注', name: 'leaveremark', index: 'leaveRemark', width: 80 }, 			
			{ label: '批示主管', name: 'commander', index: 'commander', width: 80 }, 			
			{ label: '主管批示内容', name: 'commandinfo', index: 'commandinfo', width: 80 },		
			{ label: '请假状态', name: 'state', index: 'state', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showLeaveinfoDiv:true,
		showList: true,
		title: null,
		leaveinfo: {},
		employee:{
			name:null
		},
		q:{
			startDate:null,
			endDate:null
		}
	},
	methods: {
		query: function () {
			
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.leaveinfo = {};
		},
		update: function (event) {
			var leaveno = getSelectedRow();
			if(leaveno == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(leaveno)
		},
		saveOrUpdate: function (event) {
			var url = vm.leaveinfo.leaveno == null ? "generator/leaveinfo/save" : "generator/leaveinfo/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.leaveinfo),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var leavenos = getSelectedRows();
			if(leavenos == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "generator/leaveinfo/delete",
                    contentType: "application/json",
				    data: JSON.stringify(leavenos),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(leaveno){
			$.get(baseURL + "generator/leaveinfo/info/"+leaveno, function(r){
                vm.leaveinfo = r.leaveinfo;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
				postData:vm.q,
                page:page
            }).trigger("reloadGrid");
		},
		queryEmployee:function(){
			vm.showLeaveinfoDiv = true;
			var page = $("#LeaveinfoGrid").jqGrid('getGridParam','page');
			$("#LeaveinfoGrid").jqGrid('setGridParam',{ 
				postData:vm.employee,
                page:page
            }).trigger("reloadGrid");
		},
		queryEmployeeLayer:function(){
			layer.open({
				type: 1,
				skin: 'layui-layer-molv',
				title: "查询员工信息",
				area: ['1000px', '650px'],
				shadeClose: false,
				content: jQuery("#showLeaveinfoDiv"),
				btn: ['完成','取消'],
				btn1: function (index) {
					
					var grid = $("#LeaveinfoGrid");
				    var rowKey = grid.getGridParam("selrow");//取选中行的ID
				    var name = grid.jqGrid("getCell",rowKey,"name");//取选中行的name
				    
				    if(!rowKey){
				    	alert("请选择一条记录");
				    	return ;
				    }else{
				    	
				    	$("#employeeno").attr('value',name);
				    	vm.leaveinfo.employeeno = rowKey;
//				    	vm.$data.givingboxinfo.givepername = name;
				    	layer.close(index);
				    }
	            }
			});
		}
	}
});